# Maintainer (ArchLinux): Andrea Scarpino <andrea@archlinux.org>
# Maintainer (MSYS2): Ray Donnelly <mingw.android@gmail.com>

_realname=extra-cmake-modules
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.85.0
pkgrel=1
pkgdesc='Extra CMake modules (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://projects.kde.org/projects/kdesupport/extra-cmake-modules'
license=('LGPL')
groups=("${MINGW_PACKAGE_PREFIX}-kf5")
depends=("${MINGW_PACKAGE_PREFIX}-cmake"
         "${MINGW_PACKAGE_PREFIX}-png2ico")
makedepends=("${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx"
             "${MINGW_PACKAGE_PREFIX}-python-requests")
source=("https://download.kde.org/stable/frameworks/${pkgver%.*}/${_realname}-${pkgver}.tar.xz"{,.sig}
        "set-AUTOSTATICPLUGINS.patch"
        "tar-force-local.patch")
sha256sums=('7a4209c3b113dc50250920186a2d30b71870e11ebb92a700a611b423ce6b6634'
            'SKIP'
            '8b0a5b5d72802f095086cf2adb30d37dc1033e877c8b7d709b251ec6bf3535ab'
            '142595fb4d762ed9e1d9f32889076bb308e140ea94646b32d3f8260440bb2893')
validpgpkeys=('53E6B47B45CEA3E0D5B7457758D0EE648A48B3BB') # David Faure <faure@kde.org>

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # Make sure to update patch in git style because CMake
  # installs *.orig files if hunks are in different offset
  patch -Np1 -i "${srcdir}/set-AUTOSTATICPLUGINS.patch"
  patch -Np1 -i "${srcdir}/tar-force-local.patch"
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G "Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_HTML_DOCS=OFF \
    -DBUILD_QTHELP_DOCS=OFF \
    -DBUILD_TESTING=OFF \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --build ./ --target install
}
